<!--这是承运商组件-->
<template>
  <div style="border: 1px solid #eee;padding:10px;margin: 0 20px;">
    <!-- <div style="margin-top:20px ;margin-left: 20px;">
            <el-button type="primary" icon="el-icon-edit" @click="isShowAdd=true">新增</el-button>
              <el-button type="success">重新排序</el-button>
            <span style="display: inline-block;width: 800px;text-align: right;">共有数据{{dataNum}}条</span>
        </div> -->
    <div>
      <!-- <el-table :data="tableData" row-key="id"   border fit highlight-current-row style="width: 100%;margin-top: 20px;">
                 <el-table-column align="center" label="顺序号" width="170">
                    <template slot-scope="scope">
                      <span>{{scope.row.order}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column  align="center" label="名称">
                    <template slot-scope="scope">
                      <span>{{scope.row.name}}</span>
                    </template>
                </el-table-column>
                 <el-table-column  width="300" align="center" label="操作">
                    <template slot-scope="scope">
                <el-button size="small" type="danger" @click="deleteCarrier(scope.row.id)">删除</el-button>
              </template>
                </el-table-column>
           </el-table> -->
      <el-checkbox-group v-model="expresses" style="padding: 10px 20px;">
        <el-checkbox v-for="item in shipList" :label="item.shipId" :key="item.shipId"
                     style="margin-left:0;margin-right:30px;line-height:40px;">
          {{item.name}}
        </el-checkbox>
      </el-checkbox-group>
      <el-button v-if="permission == 3" v-loading="btnLoading" style="margin-left:30%;margin-top:20px;" type="primary"
                 icon="el-icon-check" @click="submitForm">保存
      </el-button>
    </div>
  </div>
</template>
<script>
  // import addCarrier from '../components/addCarrier.vue'
  import {mallConfig, mallConfigSave} from '@/api/goods'
  import {mall_mallInfo} from '@/utils/permission'
  export default {
    data() {
      return {
        permission: 3,
        shipList: [],
        expresses: [1, 2, 3, 4, 5, 6, 7],
        companyId: null,
        btnLoading: false
      }
    },
    mounted() {
      this.getModelPermission()
      this.getList()
    },
    methods: {
      getModelPermission() {
        this.permission = mall_mallInfo()
      },
      getList() {
        mallConfig().then(res => {
          this.shipList = res.data.data.ships
          this.companyId = res.data.data.mallConfig ? res.data.data.mallConfig.companyId : null
          this.expresses = res.data.data.mallConfig ? res.data.data.mallConfig.expresses : this.expresses
        }).catch(err => {
          console.log(err)
        })
      },
      submitForm() {
        if (this.btnLoading) {
          return
        }
        this.btnLoading = true
        var data = {data: {companyId: this.companyId, expresses: this.expresses, msg: 'expresses'}}
        mallConfigSave(data).then(res => {
          this.btnLoading = false
          this.companyId = res.data.data
          this.$message({
            type: 'success',
            message: '保存成功！'
          })
        }).catch(err => {
          console.log(err)
          this.btnLoading = false
        })
      }
    }
  }
</script>

<style scoped>

</style>
